# 抖码算法，让算法学习变得简单有趣
# 作者：老汤


class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


# 迭代
# 时间复杂度：O(n)
# 空间复杂度：O(1)
def print_list_iter(head):
    while head is not None:
        print(head.val)
        head = head.next


# 递归
def print_list(head):
    if head is None:
        return
    print(head.val)
    print_list(head.next)